package com.kehutong.wxapi.service.impl;

import com.kehutong.wxapi.request.*;
import com.kehutong.wxapi.response.*;
import com.kehutong.wxapi.service.ExternalContactService;
import com.kehutong.wxapi.util.KhtClient;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSON;
import org.coraframework.json.JSONArray;
import org.coraframework.json.JSONObject;
import org.coraframework.util.Objects;

/**
 * 客户服务类
 * 接口规则
 * 请求对象规则 名词+List/Update/Batch/Create/Delete/Get+Request
 * 响应对象规则 名词+List/Update/Batch/Create/Delete/Get+Response
 * 接口名称规则
 *
 * @author: liukunlong
 * @date: 2021-03-04 15:25
 */
public class ExternalContactServiceImpl implements ExternalContactService {
    @Inject
    private KhtClient khtClient;

    /**
     * 获取配置了客户联系功能的成员列表
     * 企业和第三方服务商可通过此接口获取配置了客户联系功能的成员列表。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_follow_user_list?access_token=ACCESS_TOKEN
     *
     * @param followUserListRequest 配置了客户联系功能的成员列表请求对象
     * @return 配置了客户联系功能的成员列表响应对象
     * @throws Exception 异常
     */
    public FollowUserListResponse getFollowUserList(FollowUserListRequest followUserListRequest) throws Exception {
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_follow_user_list", http -> {
            http.addParam("access_token", followUserListRequest.getAccessToken());
        });
        return JSON.parseObject(jsonObject.toJSONString(), FollowUserListResponse.class);
    }

    /**
     * 获取客户列表(没有客户的信息信息只有标志)
     * 企业可通过此接口获取指定成员添加的客户列表。客户是指配置了客户联系功能的成员所添加的外部联系人。没有配置客户联系功能的成员，所添加的外部联系人将不会作为客户返回。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list?access_token=ACCESS_TOKEN&userid=USERID
     *
     * @param externalContactListRequest 客户列表请求对象
     * @return 客户列表返回对象
     * @throws Exception 异常
     */
    public ExternalContactListResponse getExternalContactList(ExternalContactListRequest externalContactListRequest) throws Exception {
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/list", http -> {
            http.addParam("access_token", externalContactListRequest.getAccessToken());
            http.addParam("userid", externalContactListRequest.getUserid());
        });
        return JSON.parseObject(jsonObject.toJSONString(), ExternalContactListResponse.class);
    }


    /**
     * 获取客户详情
     * 企业可通过此接口，根据外部联系人的userid（如何获取?），拉取客户详情。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get?access_token=ACCESS_TOKEN&external_userid=EXTERNAL_USERID&cursor=CURSOR
     *
     * @param externalContactGetRequest 客户详情请求对象
     * @return 客户详情响应对象
     * @throws Exception
     */
    @Override
    public ExternalContactGetResponse getExternalContact(ExternalContactGetRequest externalContactGetRequest) throws Exception {
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get", http -> {
            http.addParam("access_token", externalContactGetRequest.getAccessToken());
            http.addParam("external_userid", externalContactGetRequest.getExternalUserid());
            if (Objects.nonNull(externalContactGetRequest.getCursor())) {
                http.addParam("cursor", externalContactGetRequest.getCursor());
            }
        });
        return JSON.parseObject(jsonObject.toJSONString(), ExternalContactGetResponse.class);
    }

    /**
     * 批量获取客户详情
     * 企业/第三方可通过此接口获取指定成员(员工)添加的客户详细信息列表。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/batch/get_by_user?access_token=ACCESS_TOKEN
     *
     * @param batchGetByUserRequest 批量获取客户详情请求对象
     * @return 批量获取客户详情响应对象
     * @throws Exception
     */
    public BatchGetByUserResponse batchGetByUser(BatchGetByUserRequest batchGetByUserRequest) throws Exception {
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/batch/get_by_user", http -> {
            http.addParam("access_token", batchGetByUserRequest.getAccessToken());
            JSONObject body = new JSONObject();

            body.put("userid", batchGetByUserRequest.getUserid());
            if (Objects.nonEmpty(batchGetByUserRequest.getCursor())) {
                body.put("cursor", batchGetByUserRequest.getCursor());
            }
            if (Objects.nonNull(batchGetByUserRequest.getLimit())) {
                body.put("limit", String.valueOf(batchGetByUserRequest.getLimit()));
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), BatchGetByUserResponse.class);
    }

    /**
     * 修改客户备注信息
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/remark?access_token=ACCESS_TOKEN
     *
     * @param externalContactRemarkUpdateRequest 修改客户备注信息请求对象
     * @return 修改客户备注信息响应对象
     * @throws Exception 异常
     */
    public ExternalContactRemarkUpdateResponse updateExternalContactRemark(ExternalContactRemarkUpdateRequest externalContactRemarkUpdateRequest) throws Exception {
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/remark", http -> {
            http.addParam("access_token", externalContactRemarkUpdateRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("userid", externalContactRemarkUpdateRequest.getUserid());
            body.put("external_userid", externalContactRemarkUpdateRequest.getExternalUserid());

            if (Objects.nonEmpty(externalContactRemarkUpdateRequest.getRemark())) {
                body.put("remark", externalContactRemarkUpdateRequest.getRemark());
            }
            if (Objects.nonEmpty(externalContactRemarkUpdateRequest.getDescription())) {
                body.put("description", externalContactRemarkUpdateRequest.getDescription());
            }
            if (Objects.nonEmpty(externalContactRemarkUpdateRequest.getRemarkCompany())) {
                body.put("remark_company", externalContactRemarkUpdateRequest.getRemarkCompany());
            }
            if (Objects.nonEmpty(externalContactRemarkUpdateRequest.getRemarkMobiles())) {
                body.put("remark_mobiles", JSONArray.parseArray(JSON.toJSONString(externalContactRemarkUpdateRequest.getRemarkMobiles())));
            }
            if (Objects.nonNull(externalContactRemarkUpdateRequest.getRemarkPicMediaid())) {
                body.put("remark_pic_mediaid", externalContactRemarkUpdateRequest.getRemarkPicMediaid());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), ExternalContactRemarkUpdateResponse.class);
    }


    /**
     * 获取企业标签库
     * 企业可通过此接口获取企业客户标签详情。
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list?access_token=ACCESS_TOKEN
     * @param corpTagListRequest 企业标签库请求对象
     * @return 企业标签库响应对象
     * @throws Exception 异常
     */
    public CorpTagListResponse getCorpTagList(CorpTagListRequest corpTagListRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_corp_tag_list", http -> {
            http.addParam("access_token", corpTagListRequest.getAccessToken());
            JSONObject body = new JSONObject();
            if (Objects.nonEmpty(corpTagListRequest.getTagId())) {
                body.put("tag_id",JSONArray.parseArray(JSON.toJSONString(corpTagListRequest.getTagId())));
            }
            if (Objects.nonNull(corpTagListRequest.getGroupId())) {
                body.put("group_id",JSONArray.parseArray(JSON.toJSONString(corpTagListRequest.getGroupId())));
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), CorpTagListResponse.class);
    }


    /**
     * 添加企业客户标签
     * 企业可通过此接口向客户标签库中添加新的标签组和标签，每个企业最多可配置3000个企业标签。
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag?access_token=ACCESS_TOKEN
     * @param corpTagAddRequest 添加企业客户标签请求对象
     * @return 添加企业客户标签响应对象
     * @throws Exception 异常
     */
    public CorpTagAddResponse addCorpTag(CorpTagAddRequest corpTagAddRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/add_corp_tag", http -> {
            http.addParam("access_token", corpTagAddRequest.getAccessToken());
            JSONObject body = new JSONObject();
            if (Objects.nonEmpty(corpTagAddRequest.getGroupId())) {
                body.put("group_id",corpTagAddRequest.getGroupId());
            }
            if (Objects.nonEmpty(corpTagAddRequest.getGroupName())) {
                body.put("group_name",corpTagAddRequest.getGroupName());
            }
            if (Objects.nonNull(corpTagAddRequest.getOrder())) {
                body.put("order",corpTagAddRequest.getOrder());
            }
            body.put("tag",JSONArray.parseArray(JSON.toJSONString(corpTagAddRequest.getTag())));
            if (Objects.nonNull(corpTagAddRequest.getAgentid())) {
                body.put("agentid",corpTagAddRequest.getAgentid());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), CorpTagAddResponse.class);
    }

    /**
     * 编辑企业客户标签
     * 企业可通过此接口向客户标签库中添加新的标签组和标签，每个企业最多可配置3000个企业标签。
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/edit_corp_tag?access_token=ACCESS_TOKEN
     * @param corpTagEditRequest 编辑企业客户标签请求对象
     * @return 编辑企业客户标签响应对象
     * @throws Exception 异常
     */
    public CorpTagEditResponse editCorpTag(CorpTagEditRequest corpTagEditRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/edit_corp_tag", http -> {
            http.addParam("access_token", corpTagEditRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("id",corpTagEditRequest.getId());

            if (Objects.nonEmpty(corpTagEditRequest.getName())) {
                body.put("name",corpTagEditRequest.getName());
            }
            if (Objects.nonNull(corpTagEditRequest.getOrder())) {
                body.put("order",corpTagEditRequest.getOrder());
            }
            if (Objects.nonNull(corpTagEditRequest.getAgentid())) {
                body.put("agentid",corpTagEditRequest.getAgentid());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), CorpTagEditResponse.class);
    }

    /**
     * 删除企业客户标签
     * 企业可通过此接口删除客户标签库中的标签，或删除整个标签组。
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_corp_tag?access_token=ACCESS_TOKEN
     * @param corpTagDeleteRequest 删除企业客户标签请求对象
     * @return 删除企业客户标签响应对象
     * @throws Exception 异常
     */
    public CorpTagDeleteResponse deleteCorpTag(CorpTagDeleteRequest corpTagDeleteRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/del_corp_tag", http -> {
            http.addParam("access_token", corpTagDeleteRequest.getAccessToken());
            JSONObject body = new JSONObject();
            if (Objects.nonEmpty(corpTagDeleteRequest.getTagId())) {
                body.put("tag_id",JSONArray.parseArray(JSON.toJSONString(corpTagDeleteRequest.getTagId())));
            }
            if (Objects.nonEmpty(corpTagDeleteRequest.getGroupId())) {
                body.put("group_id",JSONArray.parseArray(JSON.toJSONString(corpTagDeleteRequest.getGroupId())));
            }

            if (Objects.nonNull(corpTagDeleteRequest.getAgentid())) {
                body.put("agentid",corpTagDeleteRequest.getAgentid());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), CorpTagDeleteResponse.class);
    }

    /**
     * 编辑客户企业标签
     * 企业可通过此接口为指定成员的客户添加上由企业统一配置的标签。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token=ACCESS_TOKEN
     * @param markTagRequest 编辑客户企业标签请求对象
     * @return 编辑客户企业标签响应对象
     * @throws Exception 异常
     */
    public MarkTagResponse markTag(MarkTagRequest markTagRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/mark_tag", http -> {
            http.addParam("access_token", markTagRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("userid",markTagRequest.getUserid());
            body.put("external_userid",markTagRequest.getExternalUserid());
            if (Objects.nonEmpty(markTagRequest.getAddTag())) {
                body.put("add_tag",JSONArray.parseArray(JSON.toJSONString(markTagRequest.getAddTag())));
            }
            if (Objects.nonEmpty(markTagRequest.getRemoveTag())) {
                body.put("remove_tag",JSONArray.parseArray(JSON.toJSONString(markTagRequest.getRemoveTag())));
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), MarkTagResponse.class);
    }

    /**
     * 分配在职成员的客户
     * 企业可通过此接口，转接在职成员的客户给其他成员。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/transfer_customer?access_token=ACCESS_TOKEN
     * @param transferCustomerRequest 分配在职成员的客户请求对象
     * @return 分配在职成员的客户响应对象
     * @throws Exception 异常
     */
    public TransferCustomerResponse transferCustomer(TransferCustomerRequest transferCustomerRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/transfer_customer", http -> {
            http.addParam("access_token", transferCustomerRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("handover_userid",transferCustomerRequest.getHandoverUserid());
            body.put("takeover_userid",transferCustomerRequest.getTakeoverUserid());
            body.put("external_userid",JSONArray.parseArray(JSON.toJSONString(transferCustomerRequest.getExternalUserid())));
            if (Objects.nonEmpty(transferCustomerRequest.getTransferSuccessMsg())) {
                body.put("transfer_success_msg",transferCustomerRequest.getTransferSuccessMsg());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), TransferCustomerResponse.class);
    }

    /**
     * 查询客户接替状态
     * 企业和第三方可通过此接口查询在职成员的客户转接情况。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/transfer_result?access_token=ACCESS_TOKEN
     * @param transferResultRequest 查询客户接替状态请求对象
     * @return 查询客户接替状态响应对象
     * @throws Exception 异常
     */
    public TransferResultResponse transferResult(TransferResultRequest transferResultRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/transfer_result", http -> {
            http.addParam("access_token", transferResultRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("handover_userid",transferResultRequest.getHandoverUserid());
            body.put("takeover_userid",transferResultRequest.getTakeoverUserid());
            if (Objects.nonEmpty(transferResultRequest.getCursor())) {
                body.put("cursor",transferResultRequest.getCursor());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), TransferResultResponse.class);
    }

    /**
     * 获取待分配的离职成员列表
     * 企业和第三方可通过此接口，获取所有离职成员的客户列表，并可进一步调用分配离职成员的客户接口将这些客户重新分配给其他企业成员。
     * https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_unassigned_list?access_token=ACCESS_TOKEN
     * @param getUnassignedListRequest 获取待分配的离职成员列表请求对象
     * @return 获取待分配的离职成员列表响应对象
     * @throws Exception 异常
     */
    public GetUnassignedListResponse getUnassignedList(GetUnassignedListRequest getUnassignedListRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_unassigned_list", http -> {
            http.addParam("access_token", getUnassignedListRequest.getAccessToken());
            JSONObject body = new JSONObject();

            if (Objects.nonNull(getUnassignedListRequest.getPageId())) {
                body.put("page_id",getUnassignedListRequest.getPageId());
            }
            if (Objects.nonNull(getUnassignedListRequest.getPageSize())) {
                body.put("page_size",getUnassignedListRequest.getPageSize());
            }
            if (Objects.nonEmpty(getUnassignedListRequest.getCursor())) {
                body.put("cursor",getUnassignedListRequest.getCursor());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GetUnassignedListResponse.class);
    }


    /**
     * 分配离职成员的客户
     * 企业可通过此接口，分配离职成员的客户给其他成员
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/resigned/transfer_customer?access_token=ACCESS_TOKEN
     * @param resignedTransferCustomerRequest 分配离职成员的客户请求对象
     * @return 分配离职成员的客户响应对象
     * @throws Exception 异常
     */
    public ResignedTransferCustomerResponse resignedTransferCustomer(ResignedTransferCustomerRequest resignedTransferCustomerRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/resigned/transfer_customer", http -> {
            http.addParam("access_token", resignedTransferCustomerRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("handover_userid",resignedTransferCustomerRequest.getHandoverUserid());
            body.put("takeover_userid",resignedTransferCustomerRequest.getTakeoverUserid());
            if (Objects.nonEmpty(resignedTransferCustomerRequest.getExternalUserid())) {
                body.put("external_userid",JSONArray.parseArray(JSON.toJSONString(resignedTransferCustomerRequest.getExternalUserid())));
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), ResignedTransferCustomerResponse.class);
    }

    /**
     * 查询离职客户接替状态
     * 企业和第三方可通过此接口查询离职成员的客户分配情况。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/resigned/transfer_result?access_token=ACCESS_TOKEN
     * @param resignedTransferResultRequest 查询离职客户接替状态请求对象
     * @return 查询离职客户接替状态响应对象
     * @throws Exception 异常
     */
    public ResignedTransferResultResponse resignedTransferResult(ResignedTransferResultRequest resignedTransferResultRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/resigned/transfer_result", http -> {
            http.addParam("access_token", resignedTransferResultRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("handover_userid",resignedTransferResultRequest.getHandoverUserid());
            body.put("takeover_userid",resignedTransferResultRequest.getTakeoverUserid());
            if (Objects.nonEmpty(resignedTransferResultRequest.getCursor())) {
                body.put("cursor",resignedTransferResultRequest.getCursor());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), ResignedTransferResultResponse.class);
    }


    /**
     * 分配离职成员的客户群
     * 企业可通过此接口，将已离职成员为群主的群，分配给另一个客服成员。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/transfer?access_token=ACCESS_TOKEN
     * @param groupChatTransferRequest 分配离职成员的客户群请求对象
     * @return 分配离职成员的客户群响应对象
     * @throws Exception 异常
     */
    public GroupChatTransferResponse groupChatTransfer(GroupChatTransferRequest groupChatTransferRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/groupchat/transfer", http -> {
            http.addParam("access_token", groupChatTransferRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("chat_id_list",groupChatTransferRequest.getChatIdList());
            body.put("new_owner",groupChatTransferRequest.getNewOwner());
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GroupChatTransferResponse.class);
    }

    /**
     * 获取客户群列表
     * 该接口用于获取配置过客户群管理的客户群列表。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/list?access_token=ACCESS_TOKEN
     * @param groupChatListRequest 获取客户群列表请求对象
     * @return 获取客户群列表响应对象
     * @throws Exception 异常
     */
    public GroupChatListResponse groupChatList(GroupChatListRequest groupChatListRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/groupchat/list", http -> {
            http.addParam("access_token", groupChatListRequest.getAccessToken());
            JSONObject body = new JSONObject();
            if(Objects.nonNull(groupChatListRequest.getStatusFilter())){
                body.put("status_filter",groupChatListRequest.getStatusFilter());
            }
            if(Objects.nonNull(groupChatListRequest.getOwnerFilter())){
                body.put("owner_filter",groupChatListRequest.getOwnerFilter());
            }
            if (Objects.nonEmpty(groupChatListRequest.getCursor())) {
                body.put("cursor",groupChatListRequest.getCursor());
            }
            body.put("limit",groupChatListRequest.getLimit());
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GroupChatListResponse.class);
    }

    /**
     * 获取客户群详情
     * 通过客户群ID，获取详情。包括群名、群成员列表、群成员入群时间、入群方式。（客户群是由具有客户群使用权限的成员创建的外部群）
     * 需注意的是，如果发生群信息变动，会立即收到群变更事件，但是部分信息是异步处理，可能需要等一段时间调此接口才能得到最新结果
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/get?access_token=ACCESS_TOKEN
     * @param groupChatGetRequest 获取客户群详情请求对象
     * @return 获取客户群详情响应对象
     * @throws Exception 异常
     */
    public GroupChatGetResponse groupChatGet(GroupChatGetRequest groupChatGetRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/groupchat/get", http -> {
            http.addParam("access_token", groupChatGetRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("chat_id",groupChatGetRequest.getChatId());
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GroupChatGetResponse.class);
    }

    /**
     * 企业和第三方应用可通过该接口获取企业全部的发表内容。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_list?access_token=ACCESS_TOKEN
     * @param getMomentListRequest 企业和第三方应用可通过该接口获取企业全部的发表内容请求对象
     * @return 企业和第三方应用可通过该接口获取企业全部的发表内容。响应对象
     * @throws Exception 异常
     */
    public GetMomentListResponse getMomentList(GetMomentListRequest getMomentListRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_moment_list", http -> {
            http.addParam("access_token", getMomentListRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("start_time",getMomentListRequest.getStartTime());
            body.put("end_time",getMomentListRequest.getEndTime());
            if (Objects.nonEmpty(getMomentListRequest.getCreator())) {
                body.put("creator",getMomentListRequest.getCreator());
            }
            if (Objects.nonNull(getMomentListRequest.getFilterType())) {
                body.put("filter_type",getMomentListRequest.getFilterType());
            }
            if (Objects.nonEmpty(getMomentListRequest.getCursor())) {
                body.put("cursor",getMomentListRequest.getCursor());
            }
            if (Objects.nonNull(getMomentListRequest.getLimit())) {
                body.put("limit",getMomentListRequest.getLimit());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GetMomentListResponse.class);
    }

    /**
     * 企业和第三方应用可通过该接口获取企业发表的朋友圈成员执行情况
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_task?access_token=ACCESS_TOKEN
     * @param getMomentTaskRequest 企业和第三方应用可通过该接口获取企业发表的朋友圈成员执行情况请求对象
     * @return 企业和第三方应用可通过该接口获取企业发表的朋友圈成员执行情况响应对象
     * @throws Exception 异常
     */
    public GetMomentTaskResponse getMomentTask(GetMomentTaskRequest getMomentTaskRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_moment_task", http -> {
            http.addParam("access_token", getMomentTaskRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("moment_id",getMomentTaskRequest.getMomentId());
            if (Objects.nonEmpty(getMomentTaskRequest.getCursor())) {
                body.put("cursor",getMomentTaskRequest.getCursor());
            }
            if (Objects.nonNull(getMomentTaskRequest.getLimit())) {
                body.put("limit",getMomentTaskRequest.getLimit());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GetMomentTaskResponse.class);
    }

    /**
     * 获取客户朋友圈发表时选择的可见范围
     * 企业和第三方应用可通过该接口获取客户朋友圈创建时，选择的客户可见范围
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_customer_list?access_token=ACCESS_TOKEN
     * @param getMomentCustomerListRequest 获取客户朋友圈发表时选择的可见范围请求对象
     * @return 获取客户朋友圈发表时选择的可见范围响应对象
     * @throws Exception 异常
     */
    public GetMomentCustomerListResponse getMomentCustomerList(GetMomentCustomerListRequest getMomentCustomerListRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_moment_customer_list", http -> {
            http.addParam("access_token", getMomentCustomerListRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("moment_id",getMomentCustomerListRequest.getMomentId());
            if (Objects.nonEmpty(getMomentCustomerListRequest.getUserid())) {
                body.put("userid",getMomentCustomerListRequest.getUserid());
            }
            if (Objects.nonEmpty(getMomentCustomerListRequest.getCursor())) {
                body.put("cursor",getMomentCustomerListRequest.getCursor());
            }
            if (Objects.nonNull(getMomentCustomerListRequest.getLimit())) {
                body.put("limit",getMomentCustomerListRequest.getLimit());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GetMomentCustomerListResponse.class);
    }

    /**
     * 获取客户朋友圈发表后的可见客户列表
     * 企业和第三方应用可通过该接口获取客户朋友圈发表后，可在微信朋友圈中查看的客户列表
     * 请求地址：请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_send_result?access_token=ACCESS_TOKEN
     * @param getMomentSendResultRequest 获取客户朋友圈发表后的可见客户列表请求对象
     * @return 获取客户朋友圈发表后的可见客户列表响应对象
     * @throws Exception 异常
     */
    public GetMomentSendResultResponse getMomentSendResult(GetMomentSendResultRequest getMomentSendResultRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_moment_send_result", http -> {
            http.addParam("access_token", getMomentSendResultRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("moment_id",getMomentSendResultRequest.getMomentId());
            body.put("userid",getMomentSendResultRequest.getUserid());
            if (Objects.nonEmpty(getMomentSendResultRequest.getCursor())) {
                body.put("cursor",getMomentSendResultRequest.getCursor());
            }
            if (Objects.nonNull(getMomentSendResultRequest.getLimit())) {
                body.put("limit",getMomentSendResultRequest.getLimit());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GetMomentSendResultResponse.class);
    }

    /**
     * 获取客户朋友圈的互动数据
     * 企业和第三方应用可通过此接口获取客户朋友圈的互动数据。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_moment_comments?access_token=ACCESS_TOKEN
     * @param getMomentCommentsRequest 获取客户朋友圈的互动数据请求对象
     * @return 获取客户朋友圈的互动数据响应对象
     * @throws Exception 异常
     */
    public GetMomentCommentsResponse getMomentComments(GetMomentCommentsRequest getMomentCommentsRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_moment_comments", http -> {
            http.addParam("access_token", getMomentCommentsRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("moment_id",getMomentCommentsRequest.getMomentId());
            body.put("userid",getMomentCommentsRequest.getUserid());
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GetMomentCommentsResponse.class);
    }

    /**
     * 创建企业群发
     * 企业跟第三方应用可通过此接口添加企业群发消息的任务并通知成员发送给相关客户或客户群。（注：企业微信终端需升级到2.7.5版本及以上）
     * 注意：调用该接口并不会直接发送消息给客户/客户群，需要成员确认后才会执行发送（客服人员的企业微信需要升级到2.7.5及以上版本）
     * 同一个企业每个自然月内仅可针对一个客户/客户群发送4条消息，超过接收上限的客户将无法再收到群发消息。
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_msg_template?access_token=ACCESS_TOKEN
     * @param addMsgTemplateRequest 创建企业群发数据请求对象
     * @return 创建企业群发数据响应对象
     * @throws Exception 异常
     */
    public AddMsgTemplateResponse addMsgTemplate(AddMsgTemplateRequest addMsgTemplateRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/add_msg_template", http -> {
            http.addParam("access_token", addMsgTemplateRequest.getAccessToken());
            JSONObject body = new JSONObject();
            if (Objects.nonEmpty(addMsgTemplateRequest.getChatType())) {
                body.put("chat_type",addMsgTemplateRequest.getChatType());
            }

            if (Objects.nonEmpty(addMsgTemplateRequest.getExternalUserid())) {
                body.put("external_userid",addMsgTemplateRequest.getExternalUserid());
            }
            if (Objects.nonEmpty(addMsgTemplateRequest.getSender())) {
                body.put("sender",addMsgTemplateRequest.getSender());
            }
            body.put("text",addMsgTemplateRequest.getText());
            body.put("image",addMsgTemplateRequest.getImage());
            body.put("link",addMsgTemplateRequest.getLink());
            body.put("miniprogram",addMsgTemplateRequest.getMiniprogram());
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), AddMsgTemplateResponse.class);
    }

    /**
     * 企业和第三方应用可通过此接口获取企业与成员的群发记录。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_list?access_token=ACCESS_TOKEN
     * @param getGroupMsgListRequest 获取群发记录列表请求对象
     * @return 获取群发记录列表响应对象
     * @throws Exception 异常
     */
    public GetGroupMsgListResponse getGroupMsgList(GetGroupMsgListRequest getGroupMsgListRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_groupmsg_list", http -> {
            http.addParam("access_token", getGroupMsgListRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("chat_type",getGroupMsgListRequest.getChatType());
            body.put("start_time",getGroupMsgListRequest.getStartTime());
            body.put("end_time",getGroupMsgListRequest.getEndTime());
            if (Objects.nonEmpty(getGroupMsgListRequest.getCreator())) {
                body.put("creator",getGroupMsgListRequest.getCreator());
            }

            if (Objects.nonNull(getGroupMsgListRequest.getFilterType())) {
                body.put("filter_type",getGroupMsgListRequest.getFilterType());
            }
            if (Objects.nonNull(getGroupMsgListRequest.getLimit())) {
                body.put("limit",getGroupMsgListRequest.getLimit());
            }
            if (Objects.nonEmpty(getGroupMsgListRequest.getCursor())) {
                body.put("cursor",getGroupMsgListRequest.getCursor());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GetGroupMsgListResponse.class);
    }

    /**
     * 获取群发成员发送任务列表
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_task?access_token=ACCESS_TOKEN
     * @param getGroupMsgTaskRequest 获取群发成员发送任务列表请求对象
     * @return 获取群发成员发送任务列表响应对象
     * @throws Exception 异常
     */
    public GetGroupMsgTaskResponse getGroupMsgTask(GetGroupMsgTaskRequest getGroupMsgTaskRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_groupmsg_task", http -> {
            http.addParam("access_token", getGroupMsgTaskRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("msgid",getGroupMsgTaskRequest.getMsgid());
            if (Objects.nonNull(getGroupMsgTaskRequest.getLimit())) {
                body.put("limit",getGroupMsgTaskRequest.getLimit());
            }
            if (Objects.nonEmpty(getGroupMsgTaskRequest.getCursor())) {
                body.put("cursor",getGroupMsgTaskRequest.getCursor());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GetGroupMsgTaskResponse.class);
    }


    /**
     * 获取企业群发成员执行结果
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_send_result?access_token=ACCESS_TOKEN
     * @param getGroupMsgSendResultRequest 获取企业群发成员执行结果请求对象
     * @return 获取企业群发成员执行结果响应对象
     * @throws Exception 异常
     */
    public GetGroupMsgSendResultResponse getGroupMsgSendResult(GetGroupMsgSendResultRequest getGroupMsgSendResultRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_groupmsg_send_result", http -> {
            http.addParam("access_token", getGroupMsgSendResultRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("msgid",getGroupMsgSendResultRequest.getMsgid());
            body.put("userid",getGroupMsgSendResultRequest.getUserid());
            if (Objects.nonNull(getGroupMsgSendResultRequest.getLimit())) {
                body.put("limit",getGroupMsgSendResultRequest.getLimit());
            }
            if (Objects.nonEmpty(getGroupMsgSendResultRequest.getCursor())) {
                body.put("cursor",getGroupMsgSendResultRequest.getCursor());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GetGroupMsgSendResultResponse.class);
    }


    /**
     * 发送新客户欢迎语
     * 企业微信在向企业推送添加外部联系人事件时，会额外返回一个welcome_code，企业以此为凭据调用接口，即可通过成员向新添加的客户发送个性化的欢迎语。
     * 为了保证用户体验以及避免滥用，企业仅可在收到相关事件后20秒内调用，且只可调用一次。
     * 如果企业已经在管理端为相关成员配置了可用的欢迎语，则推送添加外部联系人事件时不会返回welcome_code。
     * 每次添加新客户时可能有多个企业自建应用/第三方应用收到带有welcome_code的回调事件，但仅有最先调用的可以发送成功。后续调用将返回41051（externaluser has started chatting）错误，请用户根据实际使用需求，合理设置应用可见范围，避免冲突。
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/send_welcome_msg?access_token=ACCESS_TOKEN
     * @param sendWelcomeMsgRequest 发送新客户欢迎语请求对象
     * @return 发送新客户欢迎语响应对象
     * @throws Exception 异常
     */
    public SendWelcomeMsgResponse sendWelcomeMsg(SendWelcomeMsgRequest sendWelcomeMsgRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/send_welcome_msg", http -> {
            http.addParam("access_token", sendWelcomeMsgRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("welcome_code",sendWelcomeMsgRequest.getWelcomeCode());
            body.put("text",sendWelcomeMsgRequest.getText());
            body.put("image",sendWelcomeMsgRequest.getImage());
            body.put("link",sendWelcomeMsgRequest.getLink());
            body.put("miniprogram",sendWelcomeMsgRequest.getMiniprogram());
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), SendWelcomeMsgResponse.class);
    }

    /**
     * 添加入群欢迎语素材
     * 企业可通过此API向企业的入群欢迎语素材库中添加素材。每个企业的入群欢迎语素材库中，最多容纳100个素材。
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/add?access_token=ACCESS_TOKEN
     * @param groupWelcomeTemplateAddRequest 添加入群欢迎语素材请求对象
     * @return 添加入群欢迎语素材响应对象
     * @throws Exception 异常
     */
    public GroupWelcomeTemplateAddResponse groupWelcomeTemplateAdd(GroupWelcomeTemplateAddRequest groupWelcomeTemplateAddRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/group_welcome_template/add", http -> {
            http.addParam("access_token", groupWelcomeTemplateAddRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("text",groupWelcomeTemplateAddRequest.getText());
            body.put("image",groupWelcomeTemplateAddRequest.getImage());
            body.put("link",groupWelcomeTemplateAddRequest.getLink());
            body.put("miniprogram",groupWelcomeTemplateAddRequest.getMiniprogram());
            if (Objects.nonNull(groupWelcomeTemplateAddRequest.getAgentid())) {
                body.put("agentid",groupWelcomeTemplateAddRequest.getAgentid());
            }
            if (Objects.nonNull(groupWelcomeTemplateAddRequest.getNotify())) {
                body.put("notify",groupWelcomeTemplateAddRequest.getNotify());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GroupWelcomeTemplateAddResponse.class);
    }

    /**
     * 编辑入群欢迎语素材
     * 企业可通过此API编辑入群欢迎语素材库中的素材，且仅能够编辑调用方自己创建的入群欢迎语素材。
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/edit?access_token=ACCESS_TOKEN
     * @param groupWelcomeTemplateEditRequest 编辑入群欢迎语素材请求对象
     * @return 编辑入群欢迎语素材响应对象
     * @throws Exception 异常
     */
    public GroupWelcomeTemplateEditResponse groupWelcomeTemplateEdit(GroupWelcomeTemplateEditRequest groupWelcomeTemplateEditRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/group_welcome_template/edit", http -> {
            http.addParam("access_token", groupWelcomeTemplateEditRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("template_id",groupWelcomeTemplateEditRequest.getTemplateId());
            body.put("text",groupWelcomeTemplateEditRequest.getText());
            body.put("image",groupWelcomeTemplateEditRequest.getImage());
            body.put("link",groupWelcomeTemplateEditRequest.getLink());
            body.put("miniprogram",groupWelcomeTemplateEditRequest.getMiniprogram());
            if (Objects.nonNull(groupWelcomeTemplateEditRequest.getAgentid())) {
                body.put("agentid",groupWelcomeTemplateEditRequest.getAgentid());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GroupWelcomeTemplateEditResponse.class);
    }

    /**
     * 获取入群欢迎语素材
     * 企业可通过此API获取入群欢迎语素材。
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/get?access_token=ACCESS_TOKEN
     * @param groupWelcomeTemplateGetRequest 获取入群欢迎语素材请求对象
     * @return 获取入群欢迎语素材响应对象
     * @throws Exception 异常
     */
    public GroupWelcomeTemplateGetResponse groupWelcomeTemplateGet(GroupWelcomeTemplateGetRequest groupWelcomeTemplateGetRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/group_welcome_template/get", http -> {
            http.addParam("access_token", groupWelcomeTemplateGetRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("template_id",groupWelcomeTemplateGetRequest.getTemplateId());
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GroupWelcomeTemplateGetResponse.class);
    }

    /**
     * 删除入群欢迎语素材
     * 企业可通过此API删除入群欢迎语素材，且仅能删除调用方自己创建的入群欢迎语素材
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/del?access_token=ACCESS_TOKEN
     * @param groupWelcomeTemplateDelRequest 删除入群欢迎语素材请求对象
     * @return 删除入群欢迎语素材响应对象
     * @throws Exception 异常
     */
    public GroupWelcomeTemplateDelResponse groupWelcomeTemplateGet(GroupWelcomeTemplateDelRequest groupWelcomeTemplateDelRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/group_welcome_template/del", http -> {
            http.addParam("access_token", groupWelcomeTemplateDelRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("template_id",groupWelcomeTemplateDelRequest.getTemplateId());
            if (Objects.nonNull(groupWelcomeTemplateDelRequest.getAgentid())) {
                body.put("agentid",groupWelcomeTemplateDelRequest.getAgentid());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GroupWelcomeTemplateDelResponse.class);
    }


    /**
     * 获取「联系客户统计」数据
     * 企业可通过此接口获取成员联系客户的数据，包括发起申请数、新增客户数、聊天数、发送消息数和删除/拉黑成员的客户数等指标。
     * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_user_behavior_data?access_token=ACCESS_TOKEN
     * @param getUserBehaviorDataRequest 获取「联系客户统计」数据请求对象
     * @return 获取「联系客户统计」数据响应对象
     * @throws Exception 异常
     */
    public GetUserBehaviorDataResponse getUserBehaviorData(GetUserBehaviorDataRequest getUserBehaviorDataRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/get_user_behavior_data", http -> {
            http.addParam("access_token", getUserBehaviorDataRequest.getAccessToken());
            JSONObject body = new JSONObject();
            if (Objects.nonEmpty(getUserBehaviorDataRequest.getUserid())) {
                body.put("userid",getUserBehaviorDataRequest.getUserid());
            }

            if (Objects.nonEmpty(getUserBehaviorDataRequest.getPartyid())) {
                body.put("partyid",getUserBehaviorDataRequest.getPartyid());
            }
            body.put("start_time",getUserBehaviorDataRequest.getStartTime());
            body.put("end_time",getUserBehaviorDataRequest.getEndTime());
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GetUserBehaviorDataResponse.class);
    }

    /**
     * 获取「群聊数据统计」数据按群主聚合的方式
     * 获取指定日期的统计数据。注意，企业微信仅存储180天的数据。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/statistic?access_token=ACCESS_TOKEN
     * @param groupChatStatisticRequest 获取「群聊数据统计」数据按群主聚合的方式请求对象
     * @return 获取「群聊数据统计」数据按群主聚合的方式响应对象
     * @throws Exception 异常
     */
    public GroupChatStatisticResponse groupChatStatistic(GroupChatStatisticRequest groupChatStatisticRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/groupchat/statistic", http -> {
            http.addParam("access_token", groupChatStatisticRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("day_begin_time",groupChatStatisticRequest.getDayBeginTime());

            if (Objects.nonNull(groupChatStatisticRequest.getDayEndTime())) {
                body.put("day_end_time",groupChatStatisticRequest.getDayEndTime());
            }

            if (Objects.nonNull(groupChatStatisticRequest.getOwnerFilter())) {
                body.put("owner_filter",groupChatStatisticRequest.getOwnerFilter());
            }
            if (Objects.nonNull(groupChatStatisticRequest.getOrderBy())) {
                body.put("order_by",groupChatStatisticRequest.getOrderBy());
            }

            if (Objects.nonNull(groupChatStatisticRequest.getOrderAsc())) {
                body.put("order_asc",groupChatStatisticRequest.getOrderAsc());
            }
            if (Objects.nonNull(groupChatStatisticRequest.getOffset())) {
                body.put("offset",groupChatStatisticRequest.getOffset());
            }
            if (Objects.nonNull(groupChatStatisticRequest.getLimit())) {
                body.put("limit",groupChatStatisticRequest.getLimit());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GroupChatStatisticResponse.class);
    }


    /**
     * 获取「群聊数据统计」数据按自然日聚合的方式
     * 获取指定日期的统计数据。注意，企业微信仅存储180天的数据。
     * 请求地址：https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/statistic_group_by_day?access_token=ACCESS_TOKEN
     * @param groupChatStatisticGroupByDayRequest 获取「群聊数据统计」数据按自然日聚合的方式请求对象
     * @return 获取「群聊数据统计」数据按自然日聚合的方式响应对象
     * @throws Exception 异常
     */
    public GroupChatStatisticGroupByDayResponse groupChatStatisticGroupByDay(GroupChatStatisticGroupByDayRequest groupChatStatisticGroupByDayRequest) throws Exception{
        JSONObject jsonObject = khtClient.get("/cgi-bin/externalcontact/groupchat/statistic_group_by_day", http -> {
            http.addParam("access_token", groupChatStatisticGroupByDayRequest.getAccessToken());
            JSONObject body = new JSONObject();
            body.put("day_begin_time",groupChatStatisticGroupByDayRequest.getDayBeginTime());

            if (Objects.nonNull(groupChatStatisticGroupByDayRequest.getDayEndTime())) {
                body.put("day_end_time",groupChatStatisticGroupByDayRequest.getDayEndTime());
            }

            if (Objects.nonNull(groupChatStatisticGroupByDayRequest.getOwnerFilter())) {
                body.put("owner_filter",groupChatStatisticGroupByDayRequest.getOwnerFilter());
            }
            http.setBody(body.toJSONString());
        });
        return JSON.parseObject(jsonObject.toJSONString(), GroupChatStatisticGroupByDayResponse.class);
    }
}
